import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { jwtConstants } from '../../config/constants';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor() {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      // 忽略过期时间
      ignoreExpiration: true,
      secretOrKey: jwtConstants.secret,
      jsonWebTokenOptions: {
        ignoreExpiration: true
      }
    });
  }

  async validate(payload: GolbalTypes.JWTUser) {
    return payload
  }
}
